<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/together.css" rel="stylesheet" />
	</head>

	<body>
		<!--
        	作者：592176224@qq.com
        	时间：2018-11-30
        	描述：
        
		<header class="mui-bar mui-bar-transparent" style="padding-right: 15px;">
			<a class="mui-action-back black mui-icon mui-icon-left-nav mui-pull-left"></a>
			<!--<h1 class="mui-title">我的书籍</h1>
		</header>-->

		<header class="mui-bar mui-bar-nav m_barC">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">我的书籍</h1>
		</header>

		<div class="mui-content " id="probapp">
			<!--
            	作者：592176224@qq.com
            	时间：2019-01-21
            	描述：
            
			<div class=" flex1"> 
				<div class="ws_pay_cover ">
						<img :src="list.cover_image" alt="" />
						<div class="ws_pay_title">
							<span>{{list.title}}</span>
							<div>{{list.id}}</div>
						</div>
				</div>
			</div>
			<div id="" class="flex1">
				<span class="ws_sum">
					购买数量 
					<div class="mui-numbox" data-numbox-min='0' data-numbox-max='100'>
					  <button class="mui-btn mui-numbox-btn-minus" type="button">-</button>
					  <input class="mui-numbox-input" type="number"  v-model="list.status"/>
					  <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>
					</div>
					<br/>
					<div class="money">共{{list.price}}元</div>
				</span>
			</div>
			
			<span class="ws_address">{{adds.province}}{{adds.city}}{{adds.county}}{{adds.address}} </span>
			
			
			<div class="ws_pay flex1">
				<button type="button" class="mui-btn mui-btn-outlined" @click="pay">确认支付</button>
			</div>
			-->
		</div>
		<script src="../js/jquery.min.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/req.js"></script>
		<script src="../js/muishow.js"></script>
		<script type="text/javascript">
			var bid = 0;
			var addressid = 0;
			window.onload = function() {
				mui.init();
				bid = getrequest().bookid;
				console.log(bid)
				mui.plusReady(function() {
					bid = plus.webview.currentWebview().bookid;
				})

				getgoodsdetail();
			}

			function getgoodsdetail() {
				let data2 = {
					url: "/api/Address/address_list",
					data: {
						access_token: acctoken() || ""
					}
				};
				ajax(data2, function(res2) {
					//console.log('地址', res2);
					let addstr = "暂无地址，点击设置";
					for (let i = 0; i < res2.data.length; i++) {
						
						addressid = res2.data[i].id;
						if (res2.data[i].status == 1) {
							addstr = res2.data[i].province + ' ' +
								res2.data[i].city + ' ' +
								res2.data[i].county + ' ' +
								res2.data[i].address;
						}
					}
					console.log(addstr);
					let data = {
						url: "/api/Book/shop_book_info",
						data: {
							access_token: acctoken() || "",
							id: bid
						}
					}
					ajax(data, function(res) {
						console.log(res);

						if (res.code == 1) {
							let str = '<div class=" flex1"> <div class="ws_pay_cover ">' +
								'<img src="' + hurl + '/uploads' + res.data[0].book_image + '"/>' +
								'</div></div></div></div>' +
								'<div id="" class="flex1"><span class="ws_sum">购买数量' +
								'<div class="mui-numbox" data-numbox-min="1" data-numbox-max="1000">' +
								'<button class="mui-btn mui-numbox-btn-minus" type="button">-</button>' +
								'<input class="mui-numbox-input" type="number" id="numbersid"/>' +
								'<button class="mui-btn mui-numbox-btn-plus" type="button">+</button>' +
								'</div><br/><div class="money" id="priceid">共<span style="color:red">' +
								res.data[0].price +
								'</span>元</div></span></div><span class="ws_address" onclick="goaddress()">' +
								addstr +
								'</span><div class="ws_pay flex1">' +
								'<button type="button" class="mui-btn mui-btn-outlined" onclick="pay(1)">确认支付</button>' +
								'</div>' +
								'<div class="ws_pay flex1">' +
								'<button type="button" class="mui-btn mui-btn-outlined" > <a href="'+res.data[0].pdf_path+'"></a> 下载预览</button>' +
								'</div>';
							g("probapp").innerHTML = str;
							mui(".mui-numbox").numbox();

							/*g("numbersid").addEventListener("change",function(e){
								console.log(this.value);
								
								setpriceid(res.data[0].price,this.value);
							})*/
							$("#numbersid").on("change", function(e) {
								console.log(this.value);
								setpriceid(res.data[0].price, this.value);
							})
							$("#numbersid").on("input", function(e) {
								console.log(this.value);
								setpriceid(res.data[0].price, this.value);
							})

						}
					})


				})
			}

			function setpriceid(price, num) {
				g("priceid").innerHTML = '共<span style="color:red">' + (price * num).toFixed(2) + '</span>元';

			}
			//			function goaddress(){
			//				mui.openWindow({
			//				    url: '../personal/address.html', 
			//				    id:'address'
			//				 });
			//			}
			window.addEventListener('refresh', function(e) {
				getgoodsdetail();

			})

			function goaddress() {
				let ist = {
					ist: 1
				}
				mui.openWindow({
					url: '../personal/address.html',
					id: 'address',
					extras: ist
				});

			}

			function pay() {
// 				WeixinJSBridge.invoke(
// 					'getBrandWCPayRequest', {
// 						"appId": "wx2421b1c4370ec43b", //公众号名称，由商户传入
// 						"timeStamp": "1395712654", //时间戳，自1970年以来的秒数
// 						"nonceStr": "e61463f8efa94090b1f366cccfbbb444", //随机串
// 						"package": "prepay_id=u802345jgfjsdfgsdg888",
// 						"signType": "MD5", //微信签名方式：
// 						"paySign": "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名
// 					},
// 					function(res) {
// 						if (res.err_msg == "get_brand_wcpay_request:ok") {
// 
// 						} // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
// 					});
				var that = this;
				
				ajax({
					url : '/api/Order/orderAdd',
					data : {
						access_token : acctoken() || "",
						bid : bid,
						address_id : addressid,
						preference:'',
						num: 1
					}
				}, res => {
					console.log(res)
				})
			}



			//			function pay(){
			//				mui.toast("支付功能还未开发！");
			/*
						var that = this;
						let data = {
							url:"/api/Order/orderList",
							data:{
								access_token : acctoken()||"",
								bid : that.list.sname||"",
								address_id :that.list.adds||"",
								preference:'',
								num:that.list.num
							}
						}
						ajax(data,function(res){
							if(res.code == -1){
								mui.toast(res.message);
							}
							if(res.code == 1){
								console.log(res);
//								mui.toast("修改成功")
//								return true;
							}
						})*/
			//					}
			function Preview() {
				var that = this;
				let data = {
					url: "/api/Order/orderPreview",
					data: {
						access_token: acctoken() || "",
						bid: 1 || "",
					}
				}
				ajax(data, function(res) {
					if (res.code == -1) {
						mui.toast(res.message);
					}
					if (res.code == 1) {
						console.log(res);
						that.list = res.data[0].book_info[0];
						that.adds = res.data[0].address_list[0];
					}
				})

			}
		</script>
	</body>

</html>
